package com.booking.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.booking.bean.Food;
import com.booking.bean.Food_PageBean;
import com.booking.dao.FoodDAO;
import com.booking.service.FoodQueryService;


@Service
public class FoodQueryServiceImpl implements FoodQueryService {

	@Autowired
	private FoodDAO foodDao;
	
	@Override
	public Food_PageBean<Food> findByPage(Integer currentPage,int pageSize,Integer sId) {
		
		Food_PageBean<Food> pageBean = new Food_PageBean<Food>();
        //总记录数
        int allRow = foodDao.findCount();
        //当前页开始记录
        int offset = pageBean.countOffset(currentPage,pageSize);  
        //分页查询结果集
        List<Food> list = foodDao.findByPage(offset, pageSize,sId); 

        pageBean.setPageNo(currentPage);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecords(allRow);
        pageBean.setList(list);
        pageBean.setsId(sId);
        
		
		return pageBean;
	}

	@Override
	public Food findById(Integer foodId) {
		Food food = foodDao.findById(foodId);
		
		return food;
	}

	@Override
	public String saveFood(Food food) {
		
		String result = foodDao.saveFood(food);
		
		return result; 
			
	}

	@Override
	public List<Food> queryFood(Integer sellerId) {
		List<Food> food = foodDao.queryFood(sellerId);
		
		return food;
	}

	public void deleteByIds(String ids) {
		foodDao.deleteByIds(ids);
	}

	@Override
	public String updateFood(Food food) {
		String result = foodDao.updateFood(food);
		
		return result; 
	}
}
